/*
 * Copyright (c) 2009. Silenus Consultoria, S.L.
 */
package es.silenus.detecta.model;

/**
 * A user role.
 *
 * @author <a href="mailto:malonso@silenus-consultoria.es">Mariano Alonso</a>
 * @since 22-mar-2009 11:04:04
 */
public enum Role implements IntegerEnumeration, java.io.Serializable {
/**
   * Anonymous user.
   */
	ROLE_ANONYMOUS(-1, "role.anonymous"), 
/**
   * Global administrator.
   */
	ROLE_ADMINISTRATOR(1, "role.administrator"), 
/**
   * Organization administrator.
   */
	ROLE_ORGANIZATION_ADMINISTRATOR(2, "role.organization.admin"), 

/**
   * Organization designer.
   */
	ROLE_ORGANIZATION_DESIGNER(3, "role.organization.designer"), 
/**
   * Organization user.
   */
	ROLE_ORGANIZATION_USER(4, "role.organization.user");
	/**
	 * The identifier.
	 */
	private final int id;

	/**
	 * The name.
	 */
	private final String key;

/**
   * Constructor.
   *
   * @param id  the id.
   * @param key the key.
   */
	Role(final int id, final String key) {
		this.id = id;
		this.key = key;
	}

	/**
	 * Retrieves the identifier.
	 *
	 * @return the identifier.
	 */
	public int getId() {
		return this.id;
	}

	/**
	 * Retrieves the name.
	 *
	 * @return the name.
	 */
	public String getKey() {
		return this.key;
	}

	/**
	 * Retrieves a value by its identifier.
	 *
	 * @param id the id.
	 *
	 * @return the origin.
	 */
	public static Role getById(int id) {
		switch(id) {
			case 1:
				return ROLE_ADMINISTRATOR;

			case 2:
				return ROLE_ORGANIZATION_ADMINISTRATOR;

			case 3:
				return ROLE_ORGANIZATION_DESIGNER;

			case 4:
				return ROLE_ORGANIZATION_USER;
		}

		return null;
	}
}
